$(function () {
	var gridSetting={
			url: '../history/historic-process-instances',
			colModel: [			
				{ label: 'id', name: 'id', index: 'id', width: 50, key: true,sortable:false },
				{ label: '流程定义ID', name: 'processDefinitionId', index: 'processDefinitionId', width: 100 }, 			
				{ label: '业务ID', name: 'businessKey', index: 'businessKey', width: 80 }, 			
				{ label: '开始时间', name: 'startTime', index: 'startTime', width: 140 }, 			
				{ label: '结束时间', name: 'endTime', index: 'endTime', width: 140 }, 			
				{ label: '持续时间（毫秒）', name: 'durationInMillis', index: 'endTime', width: 80 }, 			
				{ label: '开始用户ID', name: 'startUserId', index: 'startUserId', width: 80 }, 			
				{ label: '删除理由', name: 'deleteReason', index: 'deleteReason', width: 80 }, 			
				{ label: '父实例ID', name: 'superProcessInstanceId', index: 'superProcessInstanceId', width: 80 }, 			
				{ label: '参数', name: 'variables', index: 'variables', width: 80 }, 			
				{ label: '所有者Id', name: 'tenantId', index: 'tenantId', width: 80 }, 			
	        ],
	        sortname:"endTime",
	        sortorder:"desc",
	}
	gridSetting=$.extend(true,baseJqGridSetting,gridSetting);
    $("#jqGrid").jqGrid(gridSetting);
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		bpmProcessInstance: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		showModel: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			var selectedRowData=getSelectedRowData()
		/*	var url='../modeler.html?modelId='+id;
			window.location.href=url;*/
			parent.layer.open({
				type:2,
				offset: '50px',
				skin: 'layui-layer-molv',
				title: "查看流程状态",
				area: ['1200px', '600px'],
				shade: 0,
				shadeClose: false,
				content: ['diagram-viewer/index.html?processDefinitionId='+selectedRowData.processDefinitionId+'&processInstanceId='+id, 'no'],
			});
		},
		activate: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			var param={};
			param.action="activate";
			$.ajax({
				type: "PUT",
			    url: "../runtime/process-instances/"+id,
			    data: JSON.stringify(param),
			    contentType: "application/json",
			    success: function(r){
			    	alert('操作成功', function(index){
						$("#jqGrid").trigger("reloadGrid");
					});
				}
			});
		},
		suspend: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			var param={};
			param.action="suspend";
			$.ajax({
				type: "PUT",
			    url: "../runtime/process-instances/"+id,
			    data: JSON.stringify(param),
			    contentType: "application/json",
			    success: function(r){
			    	alert('操作成功', function(index){
						$("#jqGrid").trigger("reloadGrid");
					});
				}
			});
		},
		del: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "DELETE",
				    url: "../runtime/process-instances/"+id,
				    contentType: "application/json",
				    success: function(r){
				    	alert('操作成功', function(index){
							$("#jqGrid").trigger("reloadGrid");
						});
					}
				});
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});